
#__new__ is the first step of instance creation. 
#It's called first, and is responsible for returning a new instance of your class. 
#In contrast, __init__ doesn't return anything; it's only responsible for initializing the instance after it's been created.

class Word(str):
    '''Class for words, defining comparison based on word length.'''

    def __new__(cls, word):

        # Note that we have to use __new__. This is because str is an immutable
        # type, so we have to initialize it early (at creation)

        if ' ' in word:
            print "Value contains spaces. Truncating to first space."

            #Word is now all chars before first space
            word = word[:word.index(' ')] # Word is now all chars before first space
        return str.__new__(cls, word)

    #przeciazanie operatorow
    def __gt__(self, other):
        return len(self) > len(other)
    def __lt__(self, other):
        return len(self) < len(other)
    def __ge__(self, other):
        return len(self) >= len(other)
    def __le__(self, other):
        return len(self) <= len(other)

wordInstance = Word("Marcin Warycha")

print wordInstance > "Marcin"
print wordInstance < "Marcin"
print wordInstance >= "Marcin"
print wordInstance <= "Marcin"
